import os

import yaml

from .BaiZhiPaprika import data
from .Log import logger


class YamlConfig:
    DATABASE_STR = "database"

    def __init__(self):
        logger.debug(os.getcwd())
        with open('../resources/application.yml', 'r', encoding="utf-8") as r_file:
            yaml_setting: dict = yaml.safe_load(r_file);
        database_setting_dict: dict = yaml_setting.get(self.DATABASE_STR)

        logger.info(database_setting_dict)
        self.database_setting = DatabaseSetting(**database_setting_dict)


@data
class DatabaseSetting:
    type: str
    host: str
    port: int
    username: str
    password: str
    db: str
    charset: str


yaml_config = YamlConfig()

if __name__ == '__main__':
    from Log import logger

    os.chdir("../../")
    a = YamlConfig()
    logger.info(a.database_setting)
